package com.gxufl.dao;

import java.util.List;

import com.gxufl.entity.Notice;
import com.gxufl.entity.Room;
import com.gxufl.util.JdbcUtil;
import com.sun.org.apache.regexp.internal.recompile;

public class RoomDao {
	public List<Room> findList(String name){
		//List<Notice> list =new ArrayList<Notice>();
		//1.构造sql语句
		//2.调用dbutil查询sql结果
		String sql="select * from movie_room where 1";
		
		
		if(name !=null && !name.isEmpty()){
			sql=sql+" and name = '"+name+"'";
		}
		
		
			//存在bug不能正常把数据库字段内容复制给实体类
		return JdbcUtil.query(sql, Room.class);
		
		//System.out.println("到此一游");
		
	}
	
	public Room findOne(String name){
		String sql="select * from movie_room where 1";
		List<Room> list=JdbcUtil.query(sql, Room.class);
		if(list.size()==1){
			return list.get(0);
		}
		return null;
	}
	//保存方法
	public Room save(Room room) {
		// TODO: (完成)通过保存海报信息到数据库表movie_notice
		boolean isOK = JdbcUtil.save(room);
		
		Room _room = JdbcUtil.query("select * from movie_room where name = '"+room.name+"'", Room.class).get(0);
		
		if (isOK) {
			System.out.println("保存“"+room.name+"”成功");
		} else {
			System.out.println("保存“"+room.name+"”失败");
		}
		
		return _room;
	}
	
	//删除方法
	public void delete2(String name) {
		// TODO 通过删除海报信息到数据库表movie_notice
		
		Room room =findOne(name);
		
		boolean isok=JdbcUtil.delete(room.id, "room");
		
		//TODO 删除关联座位
		System.out.println(isok?"删除成功":"删除失败");
	}
}
